package com.ysz.gulimall.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;


@Configuration
public class GulimallSessionConfig {

    /**
     * @description:  设置作用域，指定Cookie名字
     * @param: []
     * @return: org.springframework.session.web.http.CookieSerializer
     * @author 杨圣志
     * @date: 2024/3/5 14:17
     */
    @Bean
    public CookieSerializer cookieSerializer() {

        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();

        //放大作用域
        cookieSerializer.setDomainName("gulimall.com");
        cookieSerializer.setCookieName("GULISESSION");

        return cookieSerializer;
    }


    /**
     * @description:  序列化数据
     * @param: []
     * @return: org.springframework.data.redis.serializer.RedisSerializer<java.lang.Object>
     * @author 杨圣志
     * @date: 2024/3/5 14:19
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }

}
